//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////// 
// decompose boundary in many ctopologies


#ifndef DECOMP_BOUNDARY_H
#define DECOMP_BOUNDARY_H

#include <vector>
#include "ctopology/topology.hpp"

using namespace std;

//
//////////////////////////////////////////////////////////////////////////
class cornerCurves
{
public:
  int adjSurf[2];
  int adjVertices[2];

  vector <int> idpts;
};


//
//////////////////////////////////////////////////////////////////////////
class decompBoundary
{
public:
  decompBoundary(void);
  ~decompBoundary(void);

  //////////////////////////////////////////////////////////////////////////
  void setBoudary (cTopology *bound)
  {
    m_topol = bound;
  }

  // process
  bool process ( );

  // out vertex
  vector <int> m_outVertex;

  // out meshes
  vector <cTopology*> m_outMeshes;
  vector <vector<int>> m_adjCurveToMeshes;
  vector <vector<int>> m_orientCurveMeshes;

  // out curves
  vector <cornerCurves> m_outCurves;


private:

  // current topology mesh
  cTopology *m_topol;

  // all corner edges 
  vector <int> m_cornerEdges;

  // functions to create surfaces, curves and edges
  //////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////// 
  
  // init all edges, nodes, and surfaces with flag = -1
  void setFlags (int flag);  

  // mark all corner edges with flag
  // send id edges to m_cornerEdges
  void markCornerEdges (int flag);  

  // mark all node vertex with starting with flag
  // send id nodes to m_outVertex
  void markNodeVertex (int flag);

  // create path surfaces and send them to m_outMeshes
  void createPatchSurfaces (int flag); 

  // create path surfaces and send them to m_outMeshes
  void createCornerCurves (int flag); 

  // check if a edge is corner 
  bool isCornerEdge (int id_edge);

  // check if a node is vertex
  bool isNodeVertex (int id_node);

  bool isEdgeCurve (int edge);

  bool isVertex (int id_node);



  // create a topology from a element with flag = -1 and set all faces with flag_id
  cTopology *createMeshFromSeedElement (int id, int flag_id);

  // build a curve from init vertex with init_edge until to find other vertex
  bool buildCurve (int flag_id, int init_vertex, int init_edge);

  // 
  int getNextEdgeCurve (int curr_edge, int curr_node);

  // obtain id surfaces adjacent to curves
  bool obtainAdjSurfToCurves ( );

  int getCurveOrient (int elem_info, int idi, int idj);

  int getNextCurveSurf (vector <int> &curves, int prev_curve, int adjnode);


};


#endif

